home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / univspl / audioc.h < prev    next >
C/C++ Source or Header  |  1999-01-12  |  3KB  |  73 lines

  1. //---------------------------------------------------------------------------
  2. #ifndef audiocH
  3. #define audiocH
  4. typedef struct
  5. {
  6.   // RIFF Header
  7.   char RIFF[4];                  // 'RIFF'
  8.   unsigned long FileLength;      // FileLenth -8 (bytes)
  9.   char FormatType[4];            // 'WAVE'
  10.   // Chunk Header
  11.   char ChunkType[4];             // 'fmt '
  12.   unsigned long ChunkLength;     // length of the fmt data
  13.   // Format header
  14.   short FormatTag;               // 1=PCM, >1 compressed
  15.   short Channels;                // 1=mono 2=stereo
  16.   unsigned long SampleRate;      // Samples per second
  17.   unsigned long BytesPerSec;     // SampleRate*BlockAlign
  18.   short BlockAlign;              // Channels*BitsPerSample / 8
  19.   short BitsPerSample;           // 8 or 16
  20.   // Data Header
  21.   char DATA[4];                  // 'data'
  22.   unsigned long DataLength;      // Length of the Data Block In Bytes
  23.   // Data Follows
  24. }  WaveHeaderStruct;
  25.  
  26.  
  27. class AudioC
  28. {
  29. public:
  30.  
  31. AudioC(char *fname);         //constructor w/auto create from file
  32. AudioC();                     //default contstructor w/ blank object
  33. AudioC(AudioC&);             //copy constructor
  34. ~AudioC();                   // destructor
  35. long ReadFile(char *fname);  // read a file in
  36. long WriteFile(char *fname); // save file
  37. // return current sample rate
  38. long GetSampleRate()       {return(Hdr.SampleRate);};
  39. // return pointer to current buffer
  40. char *GetBuffer()           {return(Buf);};
  41. // return the number of channels (1=mono 2=stereo)
  42. short GetNumChan()           {return(Hdr.Channels);};
  43. // return Bits/Sample (8 or 16)
  44. short GetBitsPerSamp()       {return(Hdr.BitsPerSample);};
  45. // return the number of samples in the buffer
  46. unsigned long GetNumSamps(){return(Hdr.DataLength*8/Hdr.BitsPerSample);};
  47. // return the number of bytes in the buffer
  48. unsigned long GetNumBytes(){return(0);};
  49. // set the Sample Rate;
  50. unsigned long SetSampleRate(unsigned long SampleRate);
  51. // copy user buffer to object
  52. char *SetBuffer(char *NewBuf,unsigned long NewNumBytes);
  53. // set the number of channels (1=mono,2=stereo)
  54. short SetNumChan(short NumChan);
  55. // set the Number of BitsPerSample (8 or 16)
  56. short SetBitsPerSamp(short BitsPerSamp);
  57. // set the number of samples in the buffer
  58. unsigned long SetNumSamps(unsigned long NumSamps);
  59.  
  60. protected:
  61.   WaveHeaderStruct Hdr;
  62.   char *Buf;
  63.   unsigned long MaxBytes;
  64.   unsigned long NumSamps;
  65. private:
  66.   void init();
  67.  
  68. };
  69.  
  70.  
  71. //---------------------------------------------------------------------------
  72. #endif
  73.